﻿using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace DirectXSim
{
    public class Camera
    {
        //Camera Position
        private float _camx;
        private float _camy; //-0.55f;
        private float _camz;//1.0f;//0.2f;

        //Camera Target
        private float _targetx;
        private float _targety;
        private float _targetz;

        public Camera()
        {
            _camx = 0.0f;
            _camy = -1.0f;
            _camz = 0.2f;

            _targetx = 0.0f;
            _targety = 1.85f;
            _targetz = 0.0f;
        }

        public Camera(float camx, float camy, float camz)
        {
            _camx = camx;
            _camy = camy;
            _camz = camz;
        }

        public Vector3 CameraVector
        {
            get { return new Vector3(_camx, _camy, _camz); }
        }

        public Vector3 TargetVector
        {
            get { return new Vector3(_targetx, _targety, _targetz); }
        }

        public void Reset()
        {
            _camx = 0.0f;
            _camy = -1.0f;
            _camz = 0.2f;
            _targetx = 0.0f;
            _targety = 1.85f;
            _targetz = 0.0f;
        }

        internal void FarView()
        {
            _camx = 0.0f;
            _camy = -5.3f;
            _camz = 1.3f;
        }

        internal void NearView()
        {
            _camx = 0.0f;
            _camy = 0.2f;
            _camz = 0.1f;
        }

        internal void Update(ref Device device)
        {
            device.Transform.View = Matrix.LookAtLH(new Vector3(_camx, _camy, _camz), new Vector3(_targetx, _targety, _targetz), new Vector3(0, 0, 1));
        }

        public float CamX
        {
            get { return _camx; }
            set { _camx = value; }
        }

        public float CamY
        {
            get { return _camy; }
            set { _camy = value; }
        }

        public float CamZ
        {
            get { return _camz; }
            set { _camz = value; }
        }
    }
}
